﻿using System;
using System.Collections.Generic;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using EvincePayroll.Data;
using EvincePayroll.Logic;
using EvincePayroll.Utility;
using System.Configuration;

namespace Evince.Service
{
    // Start the service and browse to http://<machine_name>:<port>/Service1/help to view the service's generated help page
    // NOTE: By default, a new instance of the service is created for each call; change the InstanceContextMode to Single if you want
    // a single instance of the service to process all calls.	
    [ServiceContract]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
    // NOTE: If the service is renamed, remember to update the global.asax.cs file
    public class EmployeeService
    {
        string userEmailId = ConfigurationManager.AppSettings["LoginID"].ToString();

        //[WebGet(UriTemplate = "GetEmployeeData/{employeeId}")]
        //public bool GetEmployeeData(string employeeId)
        //{
        //    try
        //    {


        //        return true;
        //    }
        //    catch (Exception ex)
        //    {

        //        throw ex;
        //    }
        //}

        [WebGet(UriTemplate = "{emailId}")]
        public EmployeeData GetUser(string emailId)
        {
            try
            {
                EmployeeLogic employeeLogic = new EmployeeLogic(emailId);
                return employeeLogic.AuthenticateUser();
            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }
        }

        [WebGet(UriTemplate = "GetEmployeeDataByEmployeeId/{employeeId}")]
        public EmployeeData GetEmployeeDataByEmployeeId(string employeeId)
        {
            EmployeeLogic employeeLogic = new EmployeeLogic(employeeId);
            return employeeLogic.GetEmployeeDataByEmployeeId(employeeId);
        }

        [WebGet(UriTemplate = "GetEmployeeList/{emailId}")]
        public List<EmployeeData> GetEmployeeList(string emailId)
        {
            try
            {
                EmployeeLogic employeeLogic = new EmployeeLogic(emailId);
                return employeeLogic.GetEmployeeList(emailId);
            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }

        }

        [WebGet(UriTemplate = "GetEmployeeListForActivation/{emailId}")]
        public List<EmployeeData> GetEmployeeListForActivation(string emailId)
        {
            try
            {
                EmployeeLogic employeeLogic = new EmployeeLogic(emailId);
                return employeeLogic.GetEmployeeListForActivation(emailId);
            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }

        }

        [WebGet(UriTemplate = "GetEmployeeData/{emailId}")]
        public EmployeeData GetEmployeeData(string emailId)
        {

            try
            {
                EmployeeLogic employeeLogic = new EmployeeLogic(userEmailId);
                return employeeLogic.GetEmployeeData(emailId);
            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }
        }

        [WebGet(UriTemplate = "updateEmployee/{id},{active},{role},{email}")]
        public bool updateEmployee(string id, string active, string role, string email)
        {
            try
            {
                EmployeeLogic empLogic = new EmployeeLogic(email);
                return empLogic.updateEmployee(Guid.Parse(id), Convert.ToInt32(active), Guid.Parse(role), email);
            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }
        }

        [WebInvoke(UriTemplate = "GetUpdatedUserProfile/{email}")]
        public bool GetUpdatedUserProfile(EmployeeData emdata, string email)
        {
            try
            {
                EmployeeLogic empLogic = new EmployeeLogic(email);
                return empLogic.GetUpdatedUserProfile(emdata, email);
            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }

        }

        [WebGet(UriTemplate = "GetUserExperince/{email}")]
        public List<ExperienceData> GetUserExperince(string email)
        {
            try
            {
                EmployeeLogic empLogic = new EmployeeLogic(email);
                return empLogic.GetUserExperince(email);
            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }


        }

        [WebInvoke(UriTemplate = "AddYourExperince/{email},{flag},{experinceId}", Method = "POST")]
        public bool AddYourExperince(ExperienceData experinceData, string email, string flag, string experinceId)
        {
            try
            {
                EmployeeLogic empLogic = new EmployeeLogic(email);
                return empLogic.AddYourExperince(experinceData, email, flag, experinceId);
            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }
        }

        [WebGet(UriTemplate = "DeleteExperience/{experienceId},{email}")]
        public bool DeleteExperience(string experienceId, string email)
        {
            try
            {
                EmployeeLogic empLogic = new EmployeeLogic(email);
                return empLogic.DeleteExperience(experienceId, email);
            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }



        }

        [WebGet(UriTemplate = "EditExperience/{experienceId},{email}")]
        public ExperienceData EditExperience(string experienceId, string email)
        {
            try
            {
                EmployeeLogic empLogic = new EmployeeLogic(email);
                return empLogic.EditExperience(experienceId, email);
            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }
        }

        [WebGet(UriTemplate = "GetExperinceByUserId/{emailId},{employeeId}")]
        public List<ExperienceData> GetExperinceByUserId(string emailId, string employeeId)
        {
            try
            {
                EmployeeLogic employee = new EmployeeLogic(emailId);
                return employee.GetExperinceByUserId(employeeId);
            }
            catch (Exception ex)
            {
                LogEngine.Log(ex.Message);
                throw;
            }
        }


    }
}